%%--------------------------------------
%% @Module: pt_19
%% Author: Auto Generated
%% Created: Thu Mar 21 20:34:21 2013
%% Description: 
%%--------------------------------------
-module(pt_19).

%%--------------------------------------
%% Include files
%%--------------------------------------
-include("common.hrl").
-include("record.hrl").
-include("proto_19_mail_announce.hrl").

%%--------------------------------------
%% Exported Functions
%%--------------------------------------
-compile(export_all).


%%--------------------------------------
%%Protocol: 19001 系统公告
%%--------------------------------------
read(19001,Bin) ->
	{Data, _} = proto_read:unpack(c2s_system_announcement, Bin),
	{c2s_system_announcement, UID} = Data,
	{ok, [UID]};

%%--------------------------------------
%%Protocol: 19003  邮件列表 c2s_get_mail
%%--------------------------------------
read(19003, Bin) ->
	{Data, _} = proto_read:unpack(c2s_get_mail, Bin),
	{c2s_get_mail, UID} = Data,
    {ok, [UID]};
 
 %%--------------------------------------
%%Protocol: 19005  领取附件
%%--------------------------------------
read(19005, Bin) ->
	{Data, _} = proto_read:unpack(c2s_get_mail_attachment, Bin),
	{c2s_get_mail_attachment, Type, MailID} = Data,
    {ok, [Type, MailID]};

%%--------------------------------------
%%Protocol: 19006  查看邮件
%%--------------------------------------
read(19006, Bin) ->
	{Data, _} = proto_read:unpack(c2s_read_mail, Bin),
	{c2s_read_mail, MailID} = Data,
    {ok, [MailID]};

%%--------------------------------------
%%Protocol: 19007  删除邮件
%%--------------------------------------
read(19007, Bin) ->
	{Data, _} = proto_read:unpack(c2s_delete_mail, Bin),
	{c2s_delete_mail, Type, MailID} = Data,
    {ok, [Type, MailID]};

%%--------------------------------------
%% undefined command
%%--------------------------------------
read(_Cmd, _R) ->
	?ERROR_MSG("~s pt_19 reading cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), _Cmd, _R]),
    {error, no_match}.

%%--------------------------------------
%%Protocol: 19001 系统公告 s2c_system_announcement
%%--------------------------------------
write(19001,[Seq, RecordData]) ->
	MsgPack = proto_write:pack(s2c_system_announcement, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(19001, ServerData)};

%% %%--------------------------------------
%% %%Protocol: 19002  系统信息(跑马灯)
%% %%--------------------------------------
write(19002, [Seq, RecordData]) ->
	MsgPack = proto_write:pack(s2c_system_marquee, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(19002, ServerData)};

%%--------------------------------------
%%Protocol: 19003  邮件列表
%%--------------------------------------
write(19003,[Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_mail, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(19003, ServerData)};

%%--------------------------------------
%%Protocol: 19004  通知玩家有新邮件
%%--------------------------------------
write(19004,[Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_new_mail, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(19004, ServerData)};

%%--------------------------------------
%%Protocol: 19005  领取附件
%%--------------------------------------
write(19005,[Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_mail_attachment, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(19005, ServerData)};

%%--------------------------------------
%%Protocol: 19006  查看邮件
%%--------------------------------------
write(19006,[Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_read_mail, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(19006, ServerData)};

%%--------------------------------------
%%Protocol: 19007  删除邮件
%%--------------------------------------
write(19007,[Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_delete_mail, RecordData),
	ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(19007, ServerData)};


%%--------------------------------------
%% undefined command 
%%--------------------------------------
write(Cmd, _R) ->
    ?ERROR_MSG("~s pt_19 writting cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), Cmd, _R]),
    {ok, pt:pack(0, <<>>)}.

%%------------------------------------
%% internal function
%%------------------------------------
pack_string(Str) ->
    BinData = tool:to_binary(Str),
    Len = byte_size(BinData),
    <<Len:16, BinData/binary>>.

any_to_binary(Any) ->
    tool:to_binary(Any).

